/*******************************************************************************
 * Copyright (c) 2011 Olexandr V. Shaposhnikov.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Olexandr V. Shaposhnikov - initial API and implementation and/or initial documentation
 *******************************************************************************/
package com.funkyroach.use.core.ast;

import java.util.Iterator;
import java.util.List;

import org.eclipse.dltk.ast.ASTNode;
import org.eclipse.dltk.ast.ASTVisitor;
import org.eclipse.dltk.ast.declarations.TypeDeclaration;

import com.funkyroach.use.core.parser.USToken;

public class USClassDeclaration extends TypeDeclaration implements USIScope {

	public USClassDeclaration(USToken t) {
		super(t.getText(), t.getStartOffset(), t.getEndOffset(), 0, 0);
	}

	protected USClassModifiers classModifiers = null;

	public void setModifiers(USClassModifiers classModifiers) {
		this.classModifiers = classModifiers;
		setModifiers(classModifiers.getModifiers());
	}

	@Override
	public int getKind() {
		return IUSASTConstants.US_AST_CLASS_DECL;
	}

	@Override
	public void traverse(ASTVisitor visitor) throws Exception {

		if (visitor.visit(this)) {
			if (this.getSuperClasses() != null) {
				@SuppressWarnings("unchecked")
                List<ASTNode> nodes = this.getSuperClasses().getChilds();
				if (nodes != null) {
					for (Iterator<ASTNode> iter = nodes.iterator(); iter
							.hasNext();) {
						ASTNode s = iter.next();
						s.traverse(visitor);
					}
				}
			}
			if (this.fBody != null) {
				fBody.traverse(visitor);
			}
			visitor.endvisit(this);
		}

	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("class ");
		sb.append(getName());
		sb.append(" extends ");
		sb.append(getSuperClasses());
		sb.append(";");
		return sb.toString();
	}

}
